package com.pansoft.openplanet.activity.child;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.pansoft.openplanet.R;
import com.pansoft.openplanet.activity.TCBaseActivity;
import com.pansoft.openplanet.widget.PassWordAlertDialog;

import net.sf.json.JSONObject;

/**
 * 授权签名详情
 *
 * @author YQS
 */

public class ChildAcceptSignDetailActivity extends TCBaseActivity implements View.OnClickListener {
    private static final String TAG = "ChildAcceptSignDetailAc";
    private TextView tvAcceptAddress;
    private TextView tvData;
    private Button buttonNext;

    private String data;
    private String address;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.open_planet_activity_accept_sign_detail);
        initView();
        initData();

    }

    private void initView() {
        tvAcceptAddress = (TextView) findViewById(R.id.tv_accept_address);
        tvData = (TextView) findViewById(R.id.tv_data);
        buttonNext = (Button) findViewById(R.id.button_next);
        buttonNext.setOnClickListener(this);
    }

    private void initData() {
        String json = getIntent().getStringExtra("scanResult");
        try {
            JSONObject jsonObject = JSONObject.fromObject(json);
            address = jsonObject.optString("walletAddress");
            tvAcceptAddress.setText(address);
            data = jsonObject.optString("data");
            tvData.setText(data);


        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @Override
    public void onClick(View view) {
        int id = view.getId();
        if (id == R.id.iv_back) {
            finish();
        } else if (id == R.id.button_next) {
            showNextDialog();
        }
    }

    private void showNextDialog() {
        //先输入密码
        PassWordAlertDialog passWordAlertDialog = new PassWordAlertDialog(this, new PassWordAlertDialog.OnEnterClick() {
            @Override
            public void passVerifySuccess(String passWord) {
                //密码验证成功后显示二维码
                AuthorizationSignEnterFragment authorizationSignEnterFragment = AuthorizationSignEnterFragment.newInstance(address, data);
                authorizationSignEnterFragment.show(getSupportFragmentManager(), TAG);
            }
        });
        passWordAlertDialog.show();

    }


}
